package com.bcu.calculus.utils;

import com.bcu.calculus.entity.Send;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class SendUtil {

    public static String genSendId() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = sdf.format(new Date());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 4; i++) {
            result += random.nextInt(10);
        }
        return newDate + result;

    }

    public static List<Send> changeSend(List<Send> sends) {

        Send sned58 = null;
        List<Send> removesendList = new ArrayList<>();
        float sumscore = 0;
        String number = "58";

        //循环sends将sends中的Tlist为58的send整合
        for (Send s : sends) {


            //判断是否是Tlist=58的send
            if(s!=null){
                if (number.equals(s.getSendTlistId())){
                    sned58 = new Send();

                    sned58.setSendTlistId(s.getSendTlistId());
                    sned58.setSendFlistId(s.getSendFlistId());
                    sned58.setSendSlistId(s.getSendSlistId());

                    if (s.getSendScore() != null) {
                        sumscore +=s.getSendScore();
                        sned58.setSendScore((double)sumscore);
                    }


                    removesendList.add(s);

                }
            }

        }

        sends.removeAll(removesendList);
        if (sned58!=null) {
            sends.add(sned58);
        }
        return sends;
    }




}



